# -*- coding:utf-8 -*-
# @Author  : Eliza
# @Time    : 2021/7/18 0:25
# @Software : RubyMine

~~~22
~12
# module  类似于class,导入到class 扩展功能
# include extant
# include: mixin module instance methods as class' instance methods 作为实例方法
# extend: mixin module instance methods as  class' class methods 作为类方法
module GameM
  Version = "0.0.1"

=begin
  def initialize(id, title, price)
    @id = id
    @title = title
    @price = price
  end
=end

  def add(a, b)
    a + b
  end

  def showVersion
    Version
  end

  #将showVersion方法定义范围静态方法
  # 意味着 只能该模块直接使用该方法
  module_function :showVersion

  def div(a, b)
    a - b
  end

  def self.show
    "Version: #{Version}"
  end

  alias ook :div #给方法起别名
end

puts "---------"
puts GameM::Version
puts GameM.showVersion
puts GameM::showVersion

puts GameM::show
puts GameM.show
# puts GameM.add() 找不到add 方法
# g1=GameM.new() 模块不存在实例化

puts "-----   Game01   include GameM---"

class Game01
  include GameM
end

# class不能直接使用
# include: mixin module instance methods as class' instance methods 模块作为实例方法
puts Game01::Version #0.0.1
# puts Game01.showVersion 报错module 的private 方法 无法使用
# Game01. 毛都没有
# 静态方法不能继承
g1 = Game01.new() #模块作为实例方法
puts g1.add(1, 2)
puts g1.div(3, 2)
puts g1.ook(3, 2)
# g1.showVersion 报错#private method `showVersion' called for
#
# include: mixin module instance methods as class' instance methods 模块作为实例方法
# extend: mixin module instance methods as  class' class methods 模块作为类方法
puts "-----   Game02 extend GameM---"

class Game02
  extend GameM
end

puts Game02.div(1, 2)
puts Game02.add(1, 4)
# Game02.showVersion 报错module 的private 方法 无法使用
g2 = Game02.new #毛都没有
puts g2.object_id
